import axios from 'axios';
import Qs from 'qs';
let tokenInject = '';
axios.interceptors.request.use(
    config => {
        const token = localStorage.getItem('token');
        if (token) {
            config.headers['Authorization'] = `Bearer ${tokenInject || token}`;
        }
        return config;
    },
    err => {
        return err;
    }
);

axios.interceptors.response.use(
    response => {
        return response;
    },
    err => {
        return err;
    }
);
const axiosInstance = axios.create({
    baseURL: '/auth/api',
    timeout: 30000, // 请求时间超过10秒视为超时
    headers: {'X-Requested-With': 'XMLHttpRequest'},
    paramsSerializer: function (params) {
        return Qs.stringify(params, {arrayFormat: 'repeat', allowDots: true});
    }
});

export default axiosInstance;
